%%%-------------------------------------------------------------------
%%% @author kk
%%% @copyright (C) 2024, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 18. 7月 2024 18:13
%%%-------------------------------------------------------------------
-module(d1_2).
-author("kk").

%% API
-export([start2/0]).

%% 查找最大值
my_max([]) -> error;
my_max([X]) -> X;  %% [X] = [X | []]
my_max([X | T]) ->
  M = my_max(T),
  if
    X > M -> X;
    true -> M
  end.

%% 查找最小值
my_min([]) -> error;
my_min([X]) -> X;
my_min([X | T]) ->
  M = my_min(T),
  if
    X < M -> X;
    true -> M
  end.

start2() ->
  Tuple = {5, 3, 9, 1, 0, 6},
  X = my_min(tuple_to_list(Tuple)),
  io:fwrite("~w", [X]).